import { defineStore } from "pinia"
import { ref, computed } from "vue"
import { LoginWxMinResult } from '@/types/login'

export const useMemberStore = defineStore('member', () => {
  // 用户信息
  const profile = ref({} as LoginWxMinResult)
  // 设置用户信息的方法
  const setProfile = (userInfo: LoginWxMinResult) => profile.value = userInfo
  // 判断用户是否登录
  const isLogin = computed(() => Boolean(profile.value.token))
  // 退出登录
  const delProfile = () => {
    setProfile({} as LoginWxMinResult)
  }
  return {
    profile,
    setProfile,
    isLogin,
    delProfile
  }
},
  {
    persist: {
      storage: {
        getItem(key) {
          return uni.getStorageSync(key)
        },
        setItem(key, value) {
          return uni.setStorageSync(key, value)
        }
      }
    }
  })